<?php

namespace App\Http\Requests\Auth;

use App\Http\Requests\Request;

class RegisterRequest extends Request
{

    /*
    * 定义错误信息
    */
    protected $error;

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        $this->error = '对不起，您没有权限注册用户！';
        //return false;
        return true;
    }

    /**
     * This method will be invoked if authorize() fails
     * 
     * @return error
     */
    public function forbiddenResponse()
    {
        return redirect('/register')->with('error_message', $this->error);
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'nickname' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'phone' => 'required|digits:11|unique:users',
            'password' => 'required|confirmed|min:6',
        ];
    }
}
